#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int q;
int count=0;
struct account
{
 char userid[10];
 char password[10];
}

acc[64];

void enter()
{
 char uid[10];
 char pid[10];
 if(count<=2)
{
printf("ENTER THE USERID");
scanf("\t%s",uid);
printf("ENTER THE PASSWORD");
scanf("\t%s",pid);
checkhash(uid,pid);
}

else
printf("\nYOUR CHANCE IS OVER");

}

// SHIFT HASHING

int checkhash(char u[10],char p[10])
{
int flag;
int flag1;
int flag2;
int ch;
int j,y,z;
int s=0;
int r,k;
for(r=0;r<strlen(u);r++)
s=s+(int)(u[r])*r;
k=s*s>>16;
printf("%d",k);
if (strcmp(acc[k].userid,u)==0)
 flag=1;
 else 
flag=0;

if(flag)
{
if (strcmp(acc[k].password,p)==0)
   flag1=1;
  else
  flag1=0;
 if(flag1)
 printf("\nYOU HAVE BEEN SIGNED IN");
 else
 {
  printf("\nWRONG PASSWORD");count++;
  printf("\nwant to enter again");
  scanf("%d",&ch);
  if(ch==1)
  enter();
 }
}
 
else
{
if(strcmp(acc[k].userid,"NULL")==0)
      printf("WRONG USERID\n");
      
 else
{
for(z=1;z<64;z++)
{
 if((strcmp(acc[(k+z)%67].userid,u)==0)&&(strcmp(acc[(k+z)%67].password,p)==0))
   {flag2=1;break;}
   else
  flag2=0;
  
  }
  if(flag2!=0)
   printf("\nYOU HAVE BEEN SIGNED IN");
 
 else
 {
  printf("\nWRONG PASSWORD");count++;
  printf("\nwant to enter again");
  scanf("%d",&ch);
  if(ch==1)
  enter();
 }
}
}
}

int main()
{
int i,x,y,z,k1;
int sum;
FILE *fp;
struct p
{
char user[10];
char pass[10];
}
e; 
fp=fopen("g.txt","r");
if(fp==NULL)
{
puts("cannot open file");
exit(1);
}
for(q=0;q<64;q++)
{
strcpy(acc[q].userid,"NULL");
strcpy(acc[q].password,"NULL");}
while(fscanf(fp,"%s %s",e.user,e.pass)!=EOF)
{
sum=0;
for(i=0;i<strlen(e.user);i++)

sum=sum+(int)(e.user[i])*i;

k1=sum*sum>>16;
for(x=0;x<67;)
{
if (strcmp(acc[(k1+x)%67].userid,"NULL")==0)
{
strcpy(acc[(k1+x)%67].userid,e.user);
strcpy(acc[(k1+x)%67].password,e.pass);
printf("%s %s %d\n",acc[(k1+x)%67].userid,acc[(k1+x)%67].password,(k1+x)%67);break;}
else
x++;
}
}
fclose(fp);
enter();
return 0;
}


